#ifndef __CORE_MEMORY_ALLOC_H__
#define __CORE_MEMORY_ALLOC_H__

/**
 *  core/memory/alloc.h
 *  pametovy manazer
 */

#include <_null.h>
#include <types.h>
#include <core/init.h>
#include <core/memory/string.h>

#define sbrk(x) ((void *)__brklvl[seg >> 12])
#define brk(newbrk) \
	(((char *)(newbrk) > (char *)(&length) - 0x200) ? \
		-1 : \
		(__brklvl[seg >> 12] = (unsigned)(newbrk), 0))

#define BUSY	    (sizeof(unsigned int)-1)
#define isbusy(x)   ((x->length)&BUSY)

typedef union {
  unsigned int length;
  char data[1];
} block;

/* pro vsechny segmenty */
static block far    *mem_alloc_bottom[16];
static unsigned int  __brklvl[16];   /*
                                      *  misto v pameti, odkud se bude alokovat,
                                      *  idealni je dat toto cislo na hodnotu
                                      *  (velikost_aplikace+1)
                                      */



int       init_alloc  (void);
void far *mem_alloc   (unsigned int length, unsigned int seg);
void      mem_free    (void far *ptr);
void far *mem_realloc (void far *ptr, unsigned int newlength);

#include <source/core/memory/alloc.c>

#endif
